package com.ls.fw.search.solrj.form.collection;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.validator.constraints.NotBlank;

import com.ls.fw.data.annotation.FwColumn;
import com.ls.fw.data.utils.FormUtil;
import com.ls.fw.search.solrj.bean.Property;

/**
 * create a collection
 * 
 * @author ls
 */
public class CreateForm {

	@NotBlank
	private String action = "CREATE";
	@NotBlank
	private String name;
	private Integer numShards;
	private String shards;
	private Integer replicationFactor = 1;
	private Integer maxShardsPerNode = 1;
	@FwColumn(name = "createNodeSet")
	private String createNodeSetStr;
	private CreateNodeSet createNodeSet;
	private Collection collection;
	private Router router;
	private Property property;
	private Boolean autoAddReplicas = false;
	private String async;
	private String rule;
	private String snitch;

	public static class Collection {

		private String configName;

		public String getConfigName() {
			return configName;
		}

		public void setConfigName(String configName) {
			this.configName = configName;
		}

		@Override
		public String toString() {
			return "Collection [configName=" + configName + "]";
		}
	}

	public static class CreateNodeSet {

		private Boolean shuffle;

		public Boolean getShuffle() {
			return shuffle;
		}

		public void setShuffle(Boolean shuffle) {
			this.shuffle = shuffle;
		}

		@Override
		public String toString() {
			return "CreateNodeSet [shuffle=" + shuffle + "]";
		}
	}

	public static class Router {
		private String name = "compositeId";
		private String field;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getField() {
			return field;
		}

		public void setField(String field) {
			this.field = field;
		}

		@Override
		public String toString() {
			return "Router [name=" + name + ", field=" + field + "]";
		}

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getNumShards() {
		return numShards;
	}

	public void setNumShards(Integer numShards) {
		this.numShards = numShards;
	}

	public String getShards() {
		return shards;
	}

	public void setShards(String shards) {
		this.shards = shards;
	}

	public Integer getReplicationFactor() {
		return replicationFactor;
	}

	public void setReplicationFactor(Integer replicationFactor) {
		this.replicationFactor = replicationFactor;
	}

	public Integer getMaxShardsPerNode() {
		return maxShardsPerNode;
	}

	public void setMaxShardsPerNode(Integer maxShardsPerNode) {
		this.maxShardsPerNode = maxShardsPerNode;
	}

	public CreateNodeSet getCreateNodeSet() {
		return createNodeSet;
	}

	public void setCreateNodeSet(CreateNodeSet createNodeSet) {
		this.createNodeSet = createNodeSet;
	}

	public Collection getCollection() {
		return collection;
	}

	public void setCollection(Collection collection) {
		this.collection = collection;
	}

	public Router getRouter() {
		return router;
	}

	public void setRouter(Router router) {
		this.router = router;
	}

	public Property getProperty() {
		return property;
	}

	public void setProperty(Property property) {
		this.property = property;
	}

	public Boolean getAutoAddReplicas() {
		return autoAddReplicas;
	}

	public void setAutoAddReplicas(Boolean autoAddReplicas) {
		this.autoAddReplicas = autoAddReplicas;
	}

	public String getAsync() {
		return async;
	}

	public void setAsync(String async) {
		this.async = async;
	}

	public String getRule() {
		return rule;
	}

	public void setRule(String rule) {
		this.rule = rule;
	}

	public String getSnitch() {
		return snitch;
	}

	public void setSnitch(String snitch) {
		this.snitch = snitch;
	}

	public String getCreateNodeSetStr() {
		return createNodeSetStr;
	}

	public void setCreateNodeSetStr(String createNodeSetStr) {
		this.createNodeSetStr = createNodeSetStr;
	}

	public static void main(String[] args) {
		CreateForm f = new CreateForm();
		CreateNodeSet createNodeSet = new CreateNodeSet();
		createNodeSet.setShuffle(true);
		f.setCreateNodeSet(createNodeSet);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("a", 1);
		map.put("b", 1);
		// f.setProperty(map);
		System.out.println(FormUtil.beanToForm(f));
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}
}
